package com.suse.service.admin.cms.controller;

import com.suse.common.base.model.param.PageQueryParam;
import com.suse.common.config.response.R;
import com.suse.service.admin.cms.model.param.AdSaveParam;
import com.suse.service.admin.cms.model.param.AdUpdateParam;
import com.suse.service.admin.cms.service.AdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 广告 前端控制器
 * </p>
 *
 * @author 辜玉彬
 * @since 2022-08-17
 */
@Api(tags = "广告接口")
@RestController
@RequestMapping("/ad")
public class AdController {

    @Resource
    private AdService adService;

    @ApiOperation(value = "获取广告列表(分页)")
    @PostMapping("/list")
    public R getAdList(@RequestBody PageQueryParam pageQueryParam) {
        return adService.getAdList(pageQueryParam);
    }

    @ApiOperation(value = "通过ID获取广告信息")
    @GetMapping("/info/{id}")
    public R getAdInfo(@PathVariable("id") String id) {
        return adService.getAdInfo(id);
    }

    @ApiOperation(value = "添加广告")
    @PostMapping("/save")
    public R saveAd(@Valid @RequestBody AdSaveParam adSaveParam) {
        return adService.saveAd(adSaveParam);
    }

    @ApiOperation(value = "修改广告")
    @PutMapping("/update")
    public R updateAd(@Valid @RequestBody AdUpdateParam adUpdateParam) {
        return adService.updateAd(adUpdateParam);
    }

}

